package com.haoxin.ai_course.modules.course.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.haoxin.ai_course.common.base.AbstractController;
import com.haoxin.ai_course.common.utils.HttpJsonResult;
import com.haoxin.ai_course.common.utils.R;
import com.haoxin.ai_course.modules.course.biz.AcArticleBusiness;
import com.haoxin.ai_course.modules.course.biz.AcCategoryBusiness;
import com.haoxin.ai_course.modules.course.entity.PO.StatisticsArticlePO;
import com.haoxin.ai_course.modules.course.entity.VO.AcArticleVO;
import com.haoxin.ai_course.modules.course.entity.VO.AcCategoryVO;

import io.lettuce.core.dynamic.annotation.Param;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;



/**
 * 文章表
 * 
 * @author xingxiangguo
 * @email bugcn@qq.com
 * @date 2022-06-06 09:44:48
 */
@RestController
@RequestMapping("/app/course/acarticle")
@Api(value="api",tags="app小程序-文章管理")
public class AcArticleController  extends AbstractController { 
	@Autowired
	AcArticleBusiness acArticleBusiness;
	@Autowired
    AcCategoryBusiness acCategoryBusiness ;
    /**
     * 列表
     */
    @GetMapping("/listByAcCategoryId")
    @ApiOperation("根据分类id查询文章列表")
    public HttpJsonResult<List<AcArticleVO>> listByAcCategoryId(@ApiParam("分类id")@RequestParam ("categoryId")int categoryId){
    	HttpJsonResult<List<AcArticleVO>> result = new HttpJsonResult<List<AcArticleVO>>();
    	try {
			result = acArticleBusiness.listByAcCategoryId(categoryId);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return result;
    }


    /**
     * 信息
     */
    @GetMapping("/info")
    @ApiOperation("根据id查询文章")
    public  HttpJsonResult<AcArticleVO> info(@ApiParam("文章id")@RequestParam ("id") Integer id){
        return acArticleBusiness.getById(id);
    }
    

    /**
     * 列表
     */
    @RequestMapping("/fullAcCategoryList")
    @ApiOperation("全部分类列表含文章")
    public HttpJsonResult<List<AcCategoryVO>> fullAcCategoryList(){
    	HttpJsonResult<List<AcCategoryVO>>  result = new  HttpJsonResult<List<AcCategoryVO>>();
        //查询列表数据
        result = acCategoryBusiness.fullList();
		return result;
    }
    /**
     * 新增文章表
     */
    @PostMapping("/articleCount")
    @ApiOperation("文章阅读人数统计")
//    @RequiresPermissions("course:acarticle:save")
    public  HttpJsonResult<Boolean>  articleCount( @ApiParam("统计对象") @RequestBody StatisticsArticlePO statisticsArticlePO){
    	HttpJsonResult<Boolean>  result = new HttpJsonResult<Boolean> ();
    	try {
			result =	acCategoryBusiness.articleCount(statisticsArticlePO,getUser());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return result;
    }
   
}
